home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Freeware / CharMap / Sources / Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  17.8 KB  |  551 lines

  1. /********************************************************
  2. ** Events.c: Handle user events coming from all sides. **
  3. **           Written by T.Pierron                      **
  4. **           10-Dec-1999                               **
  5. ********************************************************/
  6.  
  7. /* All the necessary includes: */
  8. #include <intuition/intuition.h>                /* Std datatypes */
  9. #include <intuition/intuitionbase.h>        /* To access ActiveScreen */
  10. #include <intuition/screens.h>                /* Screen information */
  11. #include <graphics/rastport.h>                /* Rastport info */
  12. #include <graphics/gfxbase.h>                    /* DefaultFont */
  13. #include <graphics/text.h>                        /* struct TextFont */
  14. #include <libraries/gadtools.h>                /* NewMenus and NewGadget */
  15. #include <libraries/commodities.h>            /* Commodity datatypes */
  16. #include <libraries/dos.h>                        /* CTRL/C signal */
  17. #include <devices/inputevent.h>                /* For raw keymap conversion */
  18.  
  19. #include "cmap.h"
  20. #define  CATCOMP_STRINGS                        /* We only need strings */
  21. #include "cmap_strings.h"                        /* Support of locale.library */
  22.  
  23. /* External variables: */
  24. extern struct IntuitionBase *IntuitionBase;
  25. extern struct GfxBase *GfxBase;
  26. extern struct Library *IconBase;
  27. extern struct Window *window;
  28. extern struct Screen *screen;
  29. extern struct NewMenu newmenu[],*checked,*checkset;
  30. extern struct Gadget *gad, *copy_gad, *paste_gad;
  31. extern struct NewWindow new_window;
  32. extern struct TextFont *font,*newfont;
  33. extern struct Menu *menu;
  34. extern WORD   xdeb,ydeb,xfin,yfin,X,Y;            /* ASCII Table position */
  35. extern UBYTE  MaxWid,Font_height,Char[];        /* Font information */
  36. extern ULONG  BoxTags[],sigwin;
  37. extern UBYTE  CharsetNum, VertSort;
  38.  
  39.  
  40. struct TTextAttr *aslfont;                            /* Returned by the ASL font requester */
  41. struct MsgPort *broker_mp = NULL;                /* Commodity message port */
  42. CxObj  *broker, *filter;                            /* Commodity and hot-key */
  43. CxMsg  *msg;                                            /* To collect messages */
  44. UBYTE  *StrBuf;                                        /* Shortcut to string gadget's buffer */
  45. struct IntuiMessage message;
  46.  
  47. struct InputEvent ie = {0,IECLASS_RAWKEY};    /* Keyboard translation map */
  48.  
  49. BYTE    CloseQuit=TRUE;                                /* True is close gadget quit the prog */
  50. BYTE  IsDraw=0,PopWin=TRUE;                        /* State of the recessed box */
  51. WORD  NumChar=-1,CustDx=0;                            /* Selected character number */
  52. ULONG cxsigflag=0;                                    /* Signal bits of the commo. */
  53.  
  54. struct NewBroker newbroker = {
  55.     NB_VERSION,
  56.     "CharMap",                            /* String to identify this commo. */
  57.     MSG_DESCLINE1_STR,
  58.     MSG_DESCLINE2_STR,
  59.     NBU_UNIQUE | NBU_NOTIFY |        /* Don't want any new commodities starting with this name. */
  60.     COF_SHOW_HIDE,                        /* If someone tries it, let me know */
  61.     0, 0, 0, 0
  62. };
  63.  
  64. void Free_commodity();
  65. void Handle_gadget(struct Gadget *);
  66.  
  67. /*** Initialize the message port of the commodity: ***/
  68. BOOL Init_commodity(int argc, char *argv[])
  69. {
  70.     UBYTE *hotkey, **ttypes;
  71.  
  72.     if(broker_mp = (void *) CreateMsgPort())
  73.     {
  74.         newbroker.nb_Port = broker_mp;
  75.         cxsigflag         = 1L << broker_mp->mp_SigBit;
  76.  
  77.         /* Get the tool-type or command line value: */
  78.         ttypes            = (UBYTE **) ArgArrayInit(argc, argv);
  79.         newbroker.nb_Pri  = (BYTE)ArgInt(ttypes, "CX_PRIORITY", 0);
  80.         CharsetNum        = (BYTE)ArgInt(ttypes, "CHARSET", 2);
  81.         hotkey            = (UBYTE *) ArgString(ttypes, "HOTKEY", "rawkey lalt control c");
  82.         CloseQuit         = ArgString(ttypes, "CLOSEQUIT", NULL)==NULL ? FALSE:TRUE;
  83.         VertSort          = ArgString(ttypes, "HORIZONTALSORT", NULL)==NULL ? TRUE:FALSE;
  84.         Parse_geometry( (UBYTE *)ArgString(ttypes, "GEOMETRY", ",,,") );
  85.  
  86.         /* Whould the user show immediatly the window ? */
  87.         if( !Stricmp(ArgString(ttypes, "CX_POPUP", Char), "NO") ) PopWin=FALSE;
  88.  
  89.         if(broker = (void *) CxBroker(&newbroker, NULL))
  90.         {
  91.             /* HotKey() is an amiga.lib function that creates a filter, sender */
  92.             /* and translate CxObject and connects them to report a hot key    */
  93.             /* press and delete its input event. */
  94.             if(filter = (void *) HotKey(hotkey, broker_mp, EVT_HOTKEY))
  95.             {
  96.                 AttachCxObj(broker, filter);        /* Add a CxObject to another's personal list */
  97.  
  98.                 if(! CxObjError(filter))
  99.                     ActivateCxObj(broker, 1L);        /* All done! */
  100.             }
  101.         }
  102.         ArgArrayDone();  /* this amiga.lib function cleans up after ArgArrayInit() */
  103.     }
  104.     return (BOOL)(broker && broker_mp);
  105. }
  106.  
  107. void Free_commodity( void )
  108. {
  109.     /* DeleteCxObjAll() is a commodities.library function that not only    **
  110.     ** deletes the CxObject pointed to in its argument, but deletes all of **
  111.     ** the CxObjects attached to it.                                       */
  112.     if(broker)
  113.     {
  114.         DeleteCxObjAll(broker);
  115.  
  116.         /* Empty the port of all CxMsgs */
  117.         while(msg = (CxMsg *)GetMsg(broker_mp))
  118.             ReplyMsg((struct Message *)msg);
  119.     }
  120.  
  121.     if(broker_mp) DeletePort(broker_mp);
  122. }
  123.  
  124. WORD OldX=0,OldY=0,Xc=0,Yc=0;
  125. /*** Move the sunken box while dragging the mouse with LMB down: ***/
  126. void Handle_box( void )
  127. {
  128.     extern WORD txtpen, fillpen, filltxt;
  129.     extern struct RastPort *RP;
  130.     extern UBYTE CharWid[], NumChars;
  131.     WORD sunken=FALSE;
  132.  
  133.     /* Center mouse position on top-left corner of the box: */
  134.     if(X<xdeb) X=0; else X -= (X-xdeb)%MaxWid;
  135.     if(Y<ydeb) Y=0; else Y -= (Y-ydeb)%Font_height;
  136.  
  137.     /* If it isn't already drawn... */
  138.     IsDraw=PRESSED;
  139.     if(X==OldX && Y==OldY) return;
  140.     BoxTags[2] = TAG_DONE;
  141.  
  142.     /* ...and inside area */
  143.     if(OldX>=xdeb && OldX<xfin && OldY>=ydeb && OldY<yfin)
  144.     {
  145.         /* Draw the sunken / beveled box: */
  146.         DR:SetAPen(RP,sunken?fillpen : 0);
  147.         RectFill(RP,OldX+1,OldY+1,OldX+MaxWid-2,OldY+Font_height-2);
  148.         SetAPen(RP,sunken?filltxt : txtpen);
  149.         Move(RP,OldX+(MaxWid-CharWid[NumChar]>>1),OldY+font->tf_Baseline+2);
  150.         *Char=(CharsetNum==3 && NumChar==127 ? 32:NumChar);
  151.         Text(RP,Char,1);
  152.  
  153.         DrawBevelBoxA(RP,OldX,OldY,MaxWid,Font_height,BoxTags);
  154.     }
  155.  
  156.     if(sunken) { Disp_charinfo(NumChar); return; } OldX=X; OldY=Y;
  157.  
  158.     if(X>=xdeb && X<xfin && Y>=ydeb && Y<yfin) {
  159.         BoxTags[2] = GTBB_Recessed;
  160.         NumChar = VertSort ? ((X-xdeb)/MaxWid<<3)+(Y-ydeb)/Font_height :
  161.                              ((Y-ydeb)/Font_height*NumChars)+(X-xdeb)/MaxWid;
  162.         if(CharsetNum >1) NumChar+=32;
  163.         if(CharsetNum==3 && NumChar>127) NumChar+=160-128;
  164.         sunken=TRUE; Xc=X; Yc=Y; goto DR;
  165.     } else {
  166.         NumChar=-1;
  167.         IsDraw=OUTSIDE_AREA;
  168.     }
  169. }
  170.  
  171. /*** Move the box using the keyboard: ***/
  172. void Handle_keyboard(UWORD code)
  173. {
  174.     /* To prevent that keyboard doesn't disturb the mouse: */
  175.     if(IsDraw > 0 || code<76 || code>79) return;
  176.     if(Xc)
  177.     {
  178.         /* Rawkey code for arrow keys: */
  179.         switch(code)
  180.         {
  181.             case 76: Yc -= Font_height; break;
  182.             case 77: Yc += Font_height; break;
  183.             case 78: Xc += MaxWid;      break;
  184.             case 79: Xc -= MaxWid;      break;
  185.         }
  186.         /* Check if cursor overrun the map: */
  187.         if(VertSort) {
  188.             /* Increase/decrease x pos, if cursor reach bottom/top of table: */
  189.             if(Yc< ydeb) { Yc=yfin-Font_height; Xc-=MaxWid; }
  190.             if(Yc>=yfin) { Yc=ydeb; Xc+=MaxWid; }
  191.             if(Xc< xdeb) Xc=xfin-MaxWid;
  192.             if(Xc>=xfin) Xc=xdeb;
  193.         }    else {
  194.             if(Xc< xdeb) { Xc=xfin-MaxWid; Yc-=Font_height; }
  195.             if(Xc>=xfin) { Xc=xdeb; Yc+=Font_height; }
  196.             if(Yc< ydeb) Yc=yfin-Font_height;
  197.             if(Yc>=yfin) Yc=ydeb;
  198.         }
  199.     } else {
  200.         /* If cursor hasn't been moved yet: */
  201.         Xc=xdeb; Yc=ydeb;
  202.     }
  203.     X=Xc; Y=Yc;
  204.     Handle_box();
  205.     /* To prevent mouse doesn't disturb the keyboard: */
  206.     IsDraw=KEYB_CONTROL;
  207. }
  208.  
  209. /*** Processes menus events: ***/
  210. void Handle_menu( LONG MenuID )
  211. {
  212.     extern struct EasyStruct Request;
  213.     extern ULONG  FontTags[];
  214.     extern UBYTE *GadTxt[];
  215.  
  216.     /** I apologize for this very bad example of ***
  217.     ***      obfuscated C programming style.     **/
  218.     switch( MenuID )
  219.     {
  220.         /**** Project Menu ****/
  221.  
  222.         case 111:/* Look if the first item isn't already selected: */
  223.                     if(checked == &newmenu[NM_FONTTYPE]) break;
  224.                     /* Take the font of the screen (Please, don't close it!): */
  225.                     font = screen->RastPort.Font; goto check;
  226.         case 112:/* Ditto: */
  227.                     if(checked == &newmenu[NM_FONTTYPE+1]) break;
  228.                     font = GfxBase->DefaultFont;
  229.         check:    /* Menus will be reallocated, change NewMenus struct. directly: */
  230.                     checked->nm_Flags &= ~CHECKED;
  231.                     checked = &newmenu[ MenuID-111+NM_FONTTYPE ];
  232.                     checked->nm_Flags |= CHECKED;
  233.                     /* Adjust cycle font-type entries: */
  234.                     if( CustDx = (FontTags[3] = MenuID-111)==2 ) FontTags[3]=0;
  235.                     FontTags[1] = (ULONG) &GadTxt[GT + (CustDx ? 0:1)];
  236.                     /* Change the charset depending of the font: */
  237.                     Init_charset(font);
  238.                     MenuID = CharsetNum+140;
  239.                     goto charset;
  240.         REDOIT:    MenuID = 113;
  241.         case 113:/* Open a ASL requester: */
  242.                     if( aslfont = (struct TTextAttr *) open_asl() )
  243.                     {
  244.                         if( newfont ) CloseFont(newfont);
  245.                         if( newfont=(void *)OpenDiskFont(aslfont) )
  246.                         {
  247.                             font = newfont;
  248.                             goto check;
  249.                         }
  250.                     }
  251.                     /* Cancel the menu selection (sorry, I don't want to use temporary variables) */
  252.                     ((struct MenuItem *)ItemAddress(menu,MENUITEM(0,0,2)))->Flags &= ~CHECKED;
  253.                     ((struct MenuItem *)ItemAddress(menu,MENUITEM(0,0,checked-&newmenu[NM_FONTTYPE])))->Flags |= CHECKED;
  254.  
  255.                     if(message.Class==GADGETUP) GT_SetGadgetAttrsA(message.IAddress,window,NULL,FontTags);
  256.                     break;
  257.                     /* Changing the charset of ASCII table: */
  258.         case 141:if(checkset == &newmenu[NM_CHARSET])   break; goto charset;
  259.         case 142:if(checkset == &newmenu[NM_CHARSET+1]) break; goto charset;
  260.         case 143:if(checkset == &newmenu[NM_CHARSET+2]) break;
  261.  
  262.         charset:    checkset->nm_Flags &= ~CHECKED;
  263.                     checkset   = &newmenu[ MenuID-141+NM_CHARSET ];
  264.                     CharsetNum = MenuID-140;
  265.                     checkset->nm_Flags |= CHECKED;
  266.                     /* Now, we can reopen our window: */
  267.                     goto new_win;
  268.  
  269.         case 21: Handle_gadget(copy_gad);
  270.         case 24:    /* Clear the text contained in the string gadget: */
  271.                     StrBuf[0]=0; RefreshGList(gad, window, NULL, 1);
  272.                     break;
  273.         case 25:    /* Jump to the next screen: */
  274.                     if( !screen->NextScreen ) break;
  275.                     screen = screen->NextScreen;
  276.                     /* Adjust the screen font, to what the screen uses: */
  277.                     if(checked == &newmenu[NM_FONTTYPE]) font = screen->RastPort.Font;
  278.         new_win:    cleanup(NULL,-1);
  279.                     /* If init failed, try to see if we can changed the font again: */
  280.                     if( setup() ) goto REDOIT;
  281.                     /* Before to move the screen, wait all it's OK: */
  282.                     ScreenToFront(screen);
  283.                     break;
  284.         case 15:    /* About menu entry: */
  285.                     EasyRequest(window, &Request, 0, CHARMAP_VERSION); break;
  286.         case 16: /* Minimize/Normalize the window: */
  287.                     ZipWindow(window);
  288.                     break;
  289.         case 17:    cleanup(NULL,-1); return;    /* Hide */
  290.         case 18:    cleanup(NULL,0);                /* Quit */
  291.  
  292.         /**** Edit Menu ****/
  293.         case 22:    Handle_gadget(copy_gad); break;
  294.         case 23:    Handle_gadget(paste_gad); break;
  295.          case 26:    VertSort=((struct MenuItem *)ItemAddress(menu,MENUITEM(1,5,0)))->Flags & CHECKED ? 1:0;
  296.                     IsDraw = NOT_PRESSED;
  297.                     Draw_ASCIIChart();         /* Sorting */
  298.     }
  299.     if(window==NULL) cleanup(0,0);
  300. }
  301.  
  302. /*** Handle all messages comming from a commo: ***/
  303. void Handle_commo(void)
  304. {
  305.     ULONG msgid, msgtype;
  306.  
  307.     /* The signal is comming from a commodity: */
  308.     while(msg = (CxMsg *)GetMsg(broker_mp))
  309.     {
  310.         msgid = CxMsgID(msg);
  311.         msgtype = CxMsgType(msg);
  312.         ReplyMsg((struct Message *)msg);
  313.  
  314.         switch(msgtype)
  315.         {
  316.             case CXM_IEVENT:
  317.                 /* Display or move the window, in the front-most screen: */
  318.                 if(msgid == EVT_HOTKEY)
  319.                 {
  320.                     front_most_screen:
  321.                     screen = IntuitionBase->ActiveScreen;
  322.                     /* If the window is already open, but not in the front-most screen, close it: */
  323.                     if(window)
  324.                         if(window->WScreen != screen) cleanup(NULL,-1);
  325.                         else {
  326.                             /* Activate and move it to front: */
  327.                             WindowToFront(window);
  328.                             ActivateWindow(window);
  329.                             /* If the window is minimize, normalize it: */
  330.                             if(window->Height<=window->BorderTop) ZipWindow(window);
  331.                             break;
  332.                         }
  333.  
  334.                     /* The screen font can be changed: */
  335.                     if(checked == &newmenu[NM_FONTTYPE]) font = screen->RastPort.Font;
  336.                     /* If something goes wrong, change the font: */
  337.                     if( setup() ) Handle_menu(113);
  338.                     ScreenToFront(screen);
  339.                 }
  340.                 break;
  341.             case CXM_COMMAND:
  342.                 switch(msgid)
  343.                 {
  344.                     case CXCMD_DISABLE:
  345.                         /* If user want to disable the commo, minimize the window: */
  346.                         if(window && window->Height>window->BorderTop) ZipWindow(window);
  347.                         ActivateCxObj(broker, 0L);
  348.                         break;
  349.                     case CXCMD_ENABLE:
  350.                         /* If user want to enable the commo, normalize it: */
  351.                         if(window && window->Height<=window->BorderTop) ZipWindow(window);
  352.                         ActivateCxObj(broker, 1L);
  353.                         break;
  354.  
  355.                     case CXCMD_APPEAR:
  356.                         /* Screen can have changed: */
  357.                         goto front_most_screen;
  358.  
  359.                     case CXCMD_DISAPPEAR:if(window) cleanup(NULL,-1);    break;
  360.                     case CXCMD_KILL:
  361.                     case CXCMD_UNIQUE:
  362.                         /* Commodities Exchange can be told not only to refuse to launch a   **
  363.                         ** commodity with a name already in use but also can notify the      **
  364.                         ** already running commodity that it happened.  It does this by      **
  365.                         ** sending a CXM_COMMAND with the ID set to CXMCMD_UNIQUE.  If the   **
  366.                         ** user tries to run a windowless commodity that is already running, **
  367.                         ** the user wants the commodity to shut down.                        */
  368.                         cleanup(0,0);
  369.                 }
  370.         }
  371.     }
  372. }
  373.  
  374. /*** Handle gadget messages ***/
  375. void Handle_gadget( struct Gadget *G )
  376. {
  377.     extern void *clipdev;
  378.     extern UBYTE GadDisable;
  379.  
  380.     /* If clipboard is unavailable: */
  381.     if((G==copy_gad || G==paste_gad) && !clipdev && !(clipdev=(void *)CBOpen(0))) {
  382.         /* Disable all related entries: */
  383.         register int i;
  384.         for(i=0; i<3; i++) {
  385.             OffMenu(window, SHIFTMENU(1)+SHIFTITEM(i)+SHIFTSUB(NOSUB));
  386.             newmenu[16+i].nm_Flags |= NM_ITEMDISABLED;
  387.         }
  388.         OffGadget(copy_gad,  window, NULL);
  389.         OffGadget(paste_gad, window, NULL);
  390.         GadDisable |= 6;
  391.         return;
  392.     }
  393.  
  394.     switch(G->GadgetID)
  395.     {
  396.         case 0: /* Clear everything in the string gadget */
  397.             Handle_menu(24);
  398.             break;
  399.         case 1: /* Copy string into clipboard: */
  400.             CBWriteFTXT(clipdev, StrBuf);
  401.             break;
  402.         case 2: /* Read string from clipboard: */
  403.             if( CBQueryFTXT(clipdev) )
  404.             {
  405.                 CBReadCHRS(clipdev, StrBuf, sti(gad)->MaxChars);
  406.                 RefreshGList(gad, window, NULL, 1);
  407.             }
  408.         case 3: /* Type of a font */
  409.             Handle_menu(111+message.Code-CustDx);
  410.             break;
  411.         case 4: /* Choose a different Charset via the cycle gadget */
  412.             Handle_menu(141+message.Code);
  413.             break;
  414.         case 10: /* String gadget realease: show info of character */
  415.             if(sti(gad)->NumChars == 1)
  416.                 Disp_charinfo( StrBuf[0] );
  417.     }
  418. }
  419.  
  420. /**** Main loop, which collects and distributes all messages: ****/
  421. void handle_input(void)
  422. {
  423.     static UBYTE buffer[8],drawit;
  424.     ULONG  sigrcvd;
  425.  
  426.     FOREVER {
  427. Deb:    sigrcvd = Wait(SIGBREAKF_CTRL_C | cxsigflag | sigwin);
  428.  
  429.         /* Look from where the signal comes: */
  430.         if(sigrcvd & SIGBREAKF_CTRL_C) cleanup(0,0);
  431.  
  432.         if(sigrcvd & cxsigflag) Handle_commo();
  433.  
  434.         if((sigrcvd & sigwin) == 0) continue;
  435.  
  436.         drawit=FALSE;
  437.         /* Use the new GadTools GT_GetIMsg() function to get input events */
  438.         while (msg = (void *) GT_GetIMsg(window->UserPort))
  439.         {
  440.             /* Copy entire message: */
  441.             CopyMem(msg,&message,sizeof(message));
  442.             X=message.MouseX; Y=message.MouseY;
  443.  
  444.             if( message.Class == MENUVERIFY && message.Code == MENUHOT && IsDraw )
  445.             {
  446.                 /* Just clears cursor */
  447.                 ((struct IntuiMessage *)msg)->Code=MENUCANCEL;
  448.                 message.Class=MOUSEBUTTONS;
  449.             }
  450.  
  451.             /* Reply to the message */
  452.             GT_ReplyIMsg(msg);
  453.  
  454.             switch(message.Class)
  455.             {
  456.                 /* The close-window gad. simply hide the main window: */
  457.                 case CLOSEWINDOW:    cleanup(NULL,CloseQuit ? 0:-1);
  458.                 case MOUSEBUTTONS:
  459.                     switch(message.Code)
  460.                     {
  461.                         /* Draw a recessed box below the mouse: */
  462.                         case SELECTDOWN: Handle_box(); break;
  463.                         /* Clear the box and add the char. in string gadget: */
  464.                         case SELECTUP:
  465.                             if(IsDraw) {
  466.                                 INS:if(NumChar>=0 && IsDraw) {
  467.                                     struct StringInfo *st = sti(gad);;
  468.  
  469.                                     if(st->NumChars>=st->MaxChars-1) strcpy(StrBuf, StrBuf+1);
  470.  
  471.                                     strcat(st->Buffer,Char);
  472.                                     RefreshGList(gad, window, NULL, 1);
  473.                                     /* If char has been keyed in, don't clear the cursor: */
  474.                                     if(IsDraw==KEYB_CONTROL) break;
  475.                                 }
  476.                                 Xc=X; Yc=Y; CL:X=Y=0; Handle_box(); IsDraw=NOT_PRESSED; drawit=0;
  477.                             }    break;
  478.                         case MENUHOT: goto CL;
  479.                     }
  480.                     break;
  481.                         
  482.                 case MOUSEMOVE: if(IsDraw>0) drawit=1; break;
  483.  
  484.                 case MENUPICK:
  485.                 {    struct MenuItem *menuitem;
  486.                     ULONG  MenuNum;
  487.  
  488.                     while (message.Code != MENUNULL)
  489.                     {
  490.                         menuitem = (struct MenuItem *) ItemAddress(menu,message.Code);
  491.                         MenuNum = (ULONG) GTMENUITEM_USERDATA(menuitem);
  492.                         Handle_menu( MenuNum );
  493.                         message.Code = (MenuNum<100 ? menuitem->NextSelect:MENUNULL);
  494.                     }
  495.                 }    break;
  496.  
  497.                 case RAWKEY:        /* Rawkey which will be Translated */
  498.                     /* If the rawkey code can be processed, don't translate it: */
  499.                     if(message.Code>127) break;
  500.                     Handle_keyboard(message.Code);
  501.  
  502.                     ie.ie_Code = message.Code;
  503.  
  504.                     /* Make sure deadkeys and qualifiers are take into account: */
  505.                     ie.ie_EventAddress = *((APTR *)message.IAddress);
  506.                     ie.ie_Qualifier = message.Qualifier;
  507.  
  508.                     /* Map RAWKEY to ANSI */
  509.                     if(MapRawKey(&ie, buffer, sizeof(buffer), NULL) <= 0) break;
  510.                     { register UBYTE code = *buffer;
  511.  
  512.                     /* Space bar inserts the highlighted char in the string gadget: */
  513.                     if(code==' ' || code=='\r') goto INS;
  514.                      if(code==27 && IsDraw) goto CL;
  515.  
  516.                     /* ESC hide the interface, whereas SHIFT ESC, quit the programm: */
  517.                     if(code==27) cleanup(NULL,IconBase && !(ie.ie_Qualifier&IEQUALIFIER_LSHIFT) && !CloseQuit?-1:0);
  518.  
  519.                     /* Tab, change the sorting method of chars: */
  520.                     else if(code=='\t')
  521.                         ((struct MenuItem *)ItemAddress(menu,MENUITEM(1,5,0)))->Flags ^= CHECKED,
  522.                         Handle_menu(26);
  523.  
  524.                     /* Remove the last inputed char or clear all the string gadget: */
  525.                     else if(code=='\b' || code==127) {
  526.                         register WORD n=(code=='\b'?sti(gad)->NumChars-1:0);
  527.                         if(n<0) break;
  528.                         StrBuf[n]=0;
  529.                         RefreshGList(gad, window, NULL, 1);
  530.                     }}
  531.                     break;
  532.                 case GADGETUP:
  533.                     Handle_gadget( (struct Gadget *)message.IAddress );
  534.                     break;
  535.  
  536.                 case REFRESHWINDOW:
  537.                     /* A minimized window has been poped-up: */
  538.                     if(window->Height>window->BorderTop) {
  539.                         Init_helpwin(window);
  540.                         if(NumChar>=0) Disp_charinfo(NumChar);
  541.                         Draw_ASCIIChart();
  542.                     }
  543.             }
  544.             /* Has the user hiden the window ? */
  545.             if(window==NULL) goto Deb;
  546.         }
  547.         /* This reduces number of IDCMP MOUSEMOVE msg to process */
  548.         if(drawit) Handle_box();
  549.     }
  550. }
  551.